package com.sky.rabc.utils;

import java.time.LocalDate;
import java.util.concurrent.atomic.AtomicInteger;

public class NumberGenerator {
    private static final AtomicInteger sequence = new AtomicInteger(0);
    private static LocalDate currentDate = LocalDate.now();
    private static final int SEQUENCE_LENGTH = 5;

    public synchronized static String GenerateNumber() {
        LocalDate now = LocalDate.now();
        // 检查是否需要重置序列号（即日期变化）
        if (!now.isEqual(currentDate)) {
            sequence.set(1); // 重置为1，因为下面会加一
            currentDate = now;
        }

        // 获取并递增序列号，不足四位前面补0
        int seq = sequence.getAndIncrement();
        String formattedSeq = String.format("%0" + SEQUENCE_LENGTH + "d", seq);
        return formattedSeq;
    }
}
